package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.EmployeeEditPasswordDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import org.apache.ibatis.annotations.*;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);



    /**
     * 新增员工
     * @param employee
     */
    @Insert("insert into employee (name, username, password, phone, sex, id_number, status, " +
            "create_time, update_time, create_user, update_user) " +
            "VALUES (#{name},#{username},#{password},#{phone},#{sex}," +
            "#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void addEmployee(Employee employee);

    /**
     * 员工分页查询
     * @param employeePageQueryDTO
     * @return
     */

    Page<Employee> queryByPage(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 员工账号启停
     * @param status
     */
    @Update("update employee set status =#{status} where id=#{id}")
    void enableAccount(Integer status,long id);

    /**
     * 根据id进行员工信息查询
     * @param id
     * @return
     */
    @Select("select * from employee where id=#{id}")
    Employee queryById(long id);

    /**
     * 修改员工信息
     * @param employee
     */
    void editEmpInfo(Employee employee);

    /**
     * 修改员工密码
     * @param empId
     * @param newPassword
     */
    @Update("update employee set password=#{newPassword} where id=#{empId}")
    void editPassword(Long empId, String newPassword);
}
